package com.example.othree.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.othree.entity.Drone2;
import com.example.othree.entity.FlightDataCount;
import com.example.othree.mapper.Drone2Mapper;
import com.example.othree.service.Drone2Service;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Service
public class Drone2ServiceImpl extends ServiceImpl<Drone2Mapper, Drone2> implements Drone2Service {

    @Resource
    Drone2Mapper drone2Mapper;

    @Override
    public Page<Drone2> getPage(int page, int pageSize) {
        // 创建分页对象
        Page<Drone2> drone2Page = new Page<>(page, pageSize);
        // 调用 MyBatis-Plus 提供的分页查询方法
        return drone2Mapper.selectPage(drone2Page, null);  // 第二个参数是查询条件，可以根据需要调整
    }

    @Override
    public IPage<Drone2> PageList(Page<Drone2> page, LambdaQueryWrapper<Drone2> lambdaQueryWrapper) {
        return this.page(page, lambdaQueryWrapper);
    }

    @Override
    public ArrayList<Drone2> getDataById(Integer id) {
        return drone2Mapper.getDataById(id);
    }

    @Override
    public List<FlightDataCount> getFlightDataCountByEquipmentName(String equipmentName){
        return drone2Mapper.selectFlightCountByEquipmentName(equipmentName);
    }

    public List<Drone2> getEquipmentByCondition(String equipmentName, String detectionDate, Integer times) {
        QueryWrapper<Drone2> queryWrapper = new QueryWrapper<>();

        // 根据equipmentName, detectionDate, times构建查询条件
        if (equipmentName != null) {
            queryWrapper.eq("equipment_name", equipmentName);
        }
        if (detectionDate != null) {
            queryWrapper.eq("detection_date", detectionDate);
        }
        if (times != null) {
            queryWrapper.eq("times", times);
        }
        return this.list(queryWrapper);  // 使用 MyBatis-Plus 提供的 list 方法
    }
}

